export { default as BaseLayer } from './base-layer'
export { default as BaseSymbolLayer, type BaseSymbolLayerOption } from './base-symbol-layer'
export { default as BaseLineLayer, type BaseLineLayerOption } from './base-line-layer'
export { default as BaseFillLayer, type BaseFillLayerOption } from './base-fill-layer'
export {
  default as SatelliteLayer,
  makeBingSatelliteLayer,
  makeTiandituSatelliteLayer
} from './satellite-layer'
export * from './geojson'
export type * from './types'

import type { Layer } from './types'
import { map } from '../core'
import { makeTiandituSatelliteLayer } from './satellite-layer'
import { registerMapLegend } from '../legend'
import { GeojsonLayers } from './geojson'

const layers: Layer[] = []
export const overlay: GeojsonLayers = new GeojsonLayers('overlay', 'overlay', true, null)

export function addLayer(layer: Layer) {
  layers.push(layer)
  layer.attach(map)
}

function setupSatelliteLayer() {
  const satelliteLayer = makeTiandituSatelliteLayer(false)
  addLayer(satelliteLayer)
  registerMapLegend({
    name: '卫星影像',
    visible: () => satelliteLayer.visible,
    setVisible(ok) {
      satelliteLayer.visible = ok
    }
  })
}

export function setupMapLayer() {
  setupSatelliteLayer()
  addLayer(overlay)
}
